package com.drguo.higouguo.service.impl;

import java.util.List;

import com.drguo.higouguo.dao.AddressDao;
import com.drguo.higouguo.entity.Address;
import com.drguo.higouguo.service.AddressService;
import com.drguo.higouguo.utils.GuoUtil;

public class AddressServiceImpl implements AddressService {
	private AddressDao addressDao;
	@Override
	public void addAddress(Address address) {
		//主键
		address.setId(GuoUtil.getId());
		if(address.getIsDefault()==null){
			address.setIsDefault("2");//1为默认地址，2为非默认地址
		}else{
			addressDao.setNotDefault(address.getUserId());
		}
		addressDao.addAddress(address);
	}
	//地址列表
	@Override
	public List<Address> getAddress(String userId) {
		
		return addressDao.getAddress(userId);
	}
	//设为默认地址
	@Override
	public void setDefault(Address address) {
		addressDao.setNotDefault(address.getUserId());
		if(address.getIsDefault().equals("1")){
			addressDao.setDefault(address.getId());
		}
	}
	
	public AddressDao getAddressDao() {
		return addressDao;
	}
	public void setAddressDao(AddressDao addressDao) {
		this.addressDao = addressDao;
	}
}
